package day10;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import day9.Student;

public class HomeWork {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<Student>();
		while (true) {
			System.out.println("请输入学生id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名：");
			String name = scanner.next();// next()输入字符串中间不能有空格  "zhang san"
			System.out.println("请输入学生年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生性别: ");
			String gender = scanner.next();
			
			Student student = new Student(id, name, age, gender);
			list.add(student);
			
			System.out.println("是否继续输入 0退出 任意其他值继续：");
			int quit = scanner.nextInt();
			if (quit == 0) {
				break;
			}
		}
		
		for (Student student : list) {
			System.out.println(student);
		}
		
		print(list); 
		
		while (true) {
			System.out.println("根据id搜索输入：1");
			System.out.println("根据name搜索输入：2");
			System.out.println("根据age搜索输入：3");
			System.out.println("根据gender搜索输入：4");
			System.out.println("退出搜索输入：0");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出搜索");
				break;
			}
			
			switch (type) {
			case 1:
				System.out.println("请输入要搜索的id：");
				int id = scanner.nextInt();
				boolean isSearchByIdFound = false;
				for (Student student : list) {
					if (student.getId() == id) {
						System.out.println(student);
						isSearchByIdFound = true;
						// break;
					}
				}
				
				if (isSearchByIdFound == false) {
					System.out.println("没有id是" + id + "的学生");
				}
				break;
			case 2:
				System.out.println("请输入要搜索的name：");
				String name = scanner.next();
				boolean isSearchByNameFound = false;
				for (Student student : list) {
					if (name.equals(student.getName())) {
						System.out.println(student);
						isSearchByNameFound = true;
						// break;
					}
				}
				
				if (isSearchByNameFound == false) {
					System.out.println("没有name是" + name + "的学生");
				}
				break;

			default:
				break;
			}
		}
	}
	
	public static void print(List<Student> list) {
		for (Student student : list) {
			System.out.println(student);
		}
	}
}
